'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 生存
 * @author sundbcn@gmail.com (sun debing)
 */

var dataApi = require('../libs/dataApi');
var _ = require('lodash');

/**
 * 根据次数获取对应的钻石消耗
 * @param  {[type]} wave_num [description]
 * @return {[type]}          [description]
 */
exports.getDiamondConsumptionConf = function (wishingtree_num) {
    var conf = dataApi.wishingtree_time.findById(wishingtree_num);
    if (!conf) {
        return 0;
    } else {
        return dataApi.wishingtree_time.findById(wishingtree_num).cost_point;
    }

};

/**
 * 根据类型获取对应的only_conf (增益过)
 * @param  {[type]} wave_num [description]
 * @return {[type]}          [description]
 */
exports.getOnlyReward = function (wishingtree_type, wishingtree_lvl, num) {
    var reward = {};
    var rewardConf = dataApi.wishingtree_lvl.findById(wishingtree_lvl);

    if (!reward) {
        return 0;
    } else {
        _.each(rewardConf, function (value) {
            var value1 = _.clone(value, true);
            if (value1.reward_type == wishingtree_type) {
                value1.reward_num = Math.ceil(value1.reward_num * _effWishtree(num));
                reward = value1;
                return true;
            }
        });
        return reward;
    }
};

/**
 * 根据等级获取产出的奖励only_list （没增益）
 * @param  {[type]} wave_num [description]
 * @return {[type]}          [description]
 */
exports.getFreeRewardlist = function (wishingtree_type, wishingtree_lvl) {
    var rewardConf = dataApi.wishingtree_lvl.findById(wishingtree_lvl);
    var only_conf = {};
    if (!rewardConf) {
        console.error('wishtree_conf type can not found:' + wishingtree_type);
        return 0;
    } else {
        _.each(rewardConf, function (value) {
            var value1 = _.clone(value, true);
            if (value1.reward_type == wishingtree_type) {
                only_conf = value1;
                return true;
            }
        });
        return only_conf;
    }
};

// 神庙增益百分比
var _effWishtree = function (num) {
    if (num > 0) {
        var eff_value = dataApi.wishingtree_effect.findById(num).value;
        return eff_value / 100;
    } else {
        return 1;
    }

};
